#ifndef SHADERPROGRAM_H
#define SHADERPROGRAM_H

#include <string>

#include "glew_context_holder.h"

class ShaderProgram : public eqtest::GLEWContextHolder
{
public:
    ShaderProgram(char const * vShaderFile, char const * fShaderFile, GLEWContext const* context);
    ~ShaderProgram();
    
    void bind();
    static void release();
    
    /**
      Get uniform variable identifier
      */
    GLint uniform(char const* name);
    
    bool success() const 
    { return overallStatus; }
    
    bool linkSuccess() const
    { return linkStatus == GL_TRUE; }
    
    bool vertexSuccess() const
    { return vShaderStatus == GL_TRUE; }
    
    bool fragmentSuccess() const
    { return fShaderStatus == GL_TRUE; }
    
    std::string linkLog() const
    { return strLinkLog; }
    
    std::string vertexLog() const
    { return strVertexLog; }
    
    std::string fragmentLog() const
    { return strFragmentLog; }
    
    std::string log() const
    { return "Vertex log:\n" + vertexLog() + "\nFragment log:\n" + fragmentLog() + "\nLink log:\n" + linkLog(); }
    
private:
    GLuint programId, vShaderId, fShaderId;
    
    GLint linkStatus, vShaderStatus, fShaderStatus;
    
    std::string strLinkLog, strVertexLog, strFragmentLog;
    
    bool overallStatus;
};

#endif // SHADERPROGRAM_H
